package com.gkoudai.open.platform.listener;

import com.gkoudai.open.platform.client.SocketIoClient;
import com.gkoudai.open.platform.handler.DataHandler;
import io.socket.client.Socket;
import io.socket.emitter.Emitter;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;

/**
 * @author : Amater
 * @date : 2024/10/28 20:35
 */
@Slf4j
@AllArgsConstructor
public class ConnectListener implements Emitter.Listener {
    private SocketIoClient socketIoClient;
    private DataHandler dataHandler;

    @Override
    public void call(Object... objects) {
        socketIoClient.getSocket().on("connectSocket", connectSocket -> {
            String s = Arrays.toString(connectSocket);
            String substring = s.substring(1, s.length() - 1);
            if (dataHandler != null) {
                dataHandler.connect(substring);
            } else {
                log.info("connectSocket message:{}",substring);
            }
        });
    }
}
